package test_achieve.web;
import constant.WebCityId;
import constant.Constant;
import cucumber.api.java.en.Given;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import util.tools.BusinessTools;
import util.tools.CommonTools;

import java.util.List;

/**
 * Created by chenkuo on 2017/7/28.
 */
public class IncreasePrice {
    OrderMain webmain = new OrderMain();
    @Given("^w获取用户账户余额：(.+)$")
    public void w获取用户账户余额(String city) throws Throwable {
        Constant.driverWeb.findElement(By.linkText("账户余额")).click();//点击账户余额
        BusinessTools.menuCityChoice(city);
        WebElement balance = Constant.driverWeb.findElement(By.xpath("//*[@id=\"app\"]/div/div/div[2]/div[2]/div/div[1]/span[2]/span[1]"));//获取账户余额
        Constant.userBalance = balance.getText();
        System.out.println("用户余额:"+Constant.userBalance);

    }

    @Given("^w对刚下的订单进行加价$")
    public void w对刚下的订单进行加价() throws Throwable {
        List<WebElement> pageElement = Constant.driverWeb.findElements(By.linkText("加价"));
        pageElement.get(0).click();//点击第一个加价按钮

    }

    @Given("^w输入加价金额:(.+)$")
    public void w输入加价金额(String fare) throws Throwable {
        Thread.sleep(1000);
        WebElement OtherFareIncrease = Constant.driverWeb.findElement(By.xpath("html/body/div[4]/div[1]/div[2]/table/tbody/tr[1]/td[6]/div[2]/div/form/div/div/div[1]/div[2]/div[2]/input"));
        Thread.sleep(2000);
        OtherFareIncrease.sendKeys(fare);


    }

    @Given("^w进入加价支付页面$")
    public void w进入加价支付页面() throws Throwable {
        Thread.sleep(2000);
        Constant.driverWeb.findElement(By.xpath("html/body/div[4]/div[1]/div[2]/table/tbody/tr[1]/td[6]/div[2]/div/form/div/div/div[2]/a[2]")).click();//点击去支付
    }

    @Given("^w选择余额支付加价:(.+)$")
    public void w选择余额支付加价(String fare) throws Throwable {
        Constant.driverWeb.findElement(By.xpath("html/body/div[4]/div/div/div[4]/button")).click();//选择去支付，默认余额支付
        Constant.orderFareIncrease=fare;
//        System.out.println("加价金额"+fare);
//        System.out.println("加价后余额支付金额"+Constant.orderBalancePayAm);
        Constant.orderAmount =String.valueOf(Integer.parseInt(Constant.orderAmount)+ Integer.parseInt(Constant.orderFareIncrease));
        Constant.orderBalancePayAm =String.valueOf(Integer.parseInt(Constant.orderBalancePayAm)+ Integer.parseInt(Constant.orderFareIncrease));
        Constant.courierTotalIncome = Float.parseFloat(Constant.orderAmount) - Constant.orderMoto;
        Thread.sleep(2000);
        webmain.w进入我的闪送中();
    }



    @Given("^w进入账户余额$")
    public void w进入账户余额() throws Throwable {
        webmain.w进入我的闪送中();
        Constant.driverWeb.findElement(By.linkText("账户余额")).click();//点击账户余额
        Thread.sleep(3000);
    }

}
